<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 500px;
            margin: 100px;
        }
        
        li {
            background: pink;
            margin-top: 10px;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
        }
        
        li a {
            float: right;
        }
        
        * {
            padding: 0;
            margin: 0;
        }
    </style>
</head>

<body>
    <div class="box">
        <textarea name="" id="" cols="30" rows="10"></textarea>
        <button type="submit">发布</button>
        <ul>
            <li>123</li>
        </ul>
    </div>
    <script>
        const bt = document.querySelector('button')
        const text = document.querySelector('textarea')
        const ul = document.querySelector('ul')
        bt.onclick = () => {
            if (text.value == '') {
                alert('请输入内容')
                return false
            }
            console.log(text.value)
            const li = document.createElement('li')
            li.innerHTML = text.value + "<a href='javascript:;'>删除</a>"
            ul.insertBefore(li, ul.children[0])
            const aList = document.querySelectorAll('a')
            for (let i = 0; i < aList.length; i++) {
                const a = aList[i];
                a.onclick = function() {
                    ul.removeChild(this.parentNode)
                }
            }
        }
    </script>
</body>

</html>